package io.renren.modules.workjobs.controller;

import java.sql.Wrapper;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.utils.Query;
import io.renren.modules.workjobs.dao.UserPositionDeliverPersonalDao;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.workjobs.entity.UserPositionDeliverPersonalEntity;
import io.renren.modules.workjobs.service.UserPositionDeliverPersonalService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author nyc
 * @email 2691778746@qq.com
 * @date 2022-03-22 09:55:49
 */
@RestController
@RequestMapping("workjobs/userpositiondeliverpersonal")
public class UserPositionDeliverPersonalController {
    @Autowired
    private UserPositionDeliverPersonalService userPositionDeliverPersonalService;
    @Autowired
    private UserPositionDeliverPersonalDao userPositionDeliverPersonalDao;


    @GetMapping("/deilver-other-info/{userId}")
    public R showDeliveryOtherInfo(@PathVariable("userId")String userId){
        QueryWrapper<UserPositionDeliverPersonalEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        List<UserPositionDeliverPersonalEntity> userPositionDeliverPersonalEntities = userPositionDeliverPersonalDao.selectList(wrapper);
        Integer deliveryCount = userPositionDeliverPersonalEntities.size();
        return R.ok().put("deliveryCount",deliveryCount);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("workjobs:userpositiondeliverpersonal:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userPositionDeliverPersonalService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("workjobs:userpositiondeliverpersonal:info")
    public R info(@PathVariable("id") Long id){
		UserPositionDeliverPersonalEntity userPositionDeliverPersonal = userPositionDeliverPersonalService.getById(id);

        return R.ok().put("userPositionDeliverPersonal", userPositionDeliverPersonal);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("workjobs:userpositiondeliverpersonal:save")
    public R save(@RequestBody UserPositionDeliverPersonalEntity userPositionDeliverPersonal){
		userPositionDeliverPersonalService.save(userPositionDeliverPersonal);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("workjobs:userpositiondeliverpersonal:update")
    public R update(@RequestBody UserPositionDeliverPersonalEntity userPositionDeliverPersonal){
		userPositionDeliverPersonalService.updateById(userPositionDeliverPersonal);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("workjobs:userpositiondeliverpersonal:delete")
    public R delete(@RequestBody Long[] ids){
		userPositionDeliverPersonalService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
